<!-- detail -->
<template>
  <div class="body">
    <van-nav-bar :title="detailObj.community">
      <template #left>
        <van-icon name="arrow-left" @click="$router.back()" />
      </template>
    </van-nav-bar>
    <div class="picture" v-if="length === 1">
      <img :src="src" alt="" />
    </div>
    <div class="picture" v-else>
      <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item v-for="(item, index) in detailObj.houseImg" :key="index">
        <img v-lazy="`http://liufusong.top:8080${item.imgSrc}`" />
      </van-swipe-item>
    </van-swipe>
    </div>
    <!-- 房屋条件 -->
    <div class="main">
      <div class="list">
        <p>{{ detailObj.title }}</p>
        <van-tag
          color="#e5f4f7"
          text-color="#7cc4d1"
          v-for="(item, index) in detailObj.tags"
          :key="index"
          >{{ item }}</van-tag
        >
      </div>
      <div class="list">
        <ul class="second">
          <li>
            <p>{{ detailObj.price }}<i>/月</i></p>
            <span>租金</span>
          </li>
          <li>
            <p>{{ detailObj.roomType }}<i>+</i></p>
            <span>房型</span>
          </li>
          <li>
            <p>{{ this.detailObj.size }}<i>平米</i></p>
            <span>面积</span>
          </li>
        </ul>
      </div>
      <div class="list">
        <ul class="third">
          <li>
            <p>装修：<span>精装</span></p>
          </li>
          <li>
            <p>
              朝向：<span>{{ direction }}</span>
            </p>
          </li>
          <li>
            <p>
              楼层：<span>{{ detailObj.floor }}</span>
            </p>
          </li>
          <li>
            <p>类型：<span>普通住宅</span></p>
          </li>
        </ul>
      </div>
    </div>
    <!-- 房屋配置 -->
    <div class="houseConfiguration">
      <p>小区：天山星城</p>
      <div>
        <baidu-map class="map" :center="pos" :zoom="15">
        </baidu-map>
      </div>
      <h5>房屋配套</h5>
      <ul>
        <li v-for="(item, index) in detailObj.supporting" :key="index">
          <p><span class="iconfont" :class="IconObj[item]"></span></p>
          <p>{{ item }}</p>
        </li>
      </ul>
    </div>
    <!-- 房源概况 -->
    <div class="houseGeneral">
      <h5>房源概况</h5>
      <div class="title">
        <div class="pictrue">
          <img src="http://liufusong.top:8080/img/avatar.png" alt="" />
        </div>
        <div class="userName">
          <p>王女士</p>
          <span>已认证房主</span>
        </div>
        <div class="msgBtn">
          <span>发消息</span>
        </div>
      </div>
      <div class="text">
        <p>
          1.周边配套齐全，地铁四号线陶然亭站，交通便利，公交云集，距离北京南站、西站都很近距离。
          2.小区规模大，配套全年，幼儿园，体育场，游泳馆，养老院，小学。
          3.人车分流，环境优美。
          4.精装两居室，居家生活方便，还有一个小书房，看房随时联系。
        </p>
      </div>
    </div>
    <div class="houseList">
      <h5>猜你喜欢</h5>
      <van-card
        price="4500 元/月"
        desc="2.32㎡/南 北/低楼层"
        title="安贞西里 3室1厅"
        thumb="http://liufusong.top:8080/img/message/1.png"
      >
        <template #tags>
          <van-tag color="#e5f4f7" text-color="#7cc4d1">随时看房</van-tag>
        </template>
      </van-card>
      <van-card
        price="7200 元/月"
        desc="83㎡/南/高楼层"
        title="天居园 2室1厅"
        thumb="http://liufusong.top:8080/img/message/2.png"
      >
        <template #tags>
          <van-tag color="#e5f4f7" text-color="#7cc4d1">近地铁</van-tag>
        </template>
      </van-card>
      <van-card
        price="4300 元/月"
        desc="52㎡/西南/低楼层"
        title="角门甲4号院 1室1厅"
        thumb="http://liufusong.top:8080/img/message/3.png"
      >
        <template #tags>
          <van-tag color="#e5f4f7" text-color="#7cc4d1">集中供暖</van-tag>
        </template>
      </van-card>
    </div>
    <div class="buttomNav">
      <van-button class="btn1" color="#fff" hairline square type="primary"  @click="fn">
        <template #default>
          <van-icon :name="flag?'star':'star-o'" color="red"/>
          <div class="btnText">收藏</div>
        </template>
        <!-- 收藏 -->
      </van-button>
      <van-button class="btn2" color="#fff" hairline square type="primary">
        <template #default>
          <div class="btnText">在线咨询</div>
        </template>
      </van-button>
      <van-button class="btn3" color="#57b67e" square type="info"
        >
        <a href="tel:400-618-4000">电话预约</a>
        </van-button
      >
    </div>
  </div>
</template>

<script>
import { houseInfoAPI, favoritesHouse, unfavoritesHouse } from '@/api'
import { Toast } from 'vant'
export default {
  data () {
    return {
      obj: JSON.parse(localStorage.getItem('item')),
      flag: false,
      detailObj: {},
      src: '',
      direction: '',
      length: 0,
      IconObj: {
        衣柜: 'icon-yigui',
        洗衣机: 'icon-xiyiji',
        空调: 'icon-kongtiao',
        天然气: 'icon-meiqitianranqi',
        冰箱: 'icon-bingxiang',
        暖气: 'icon-nuanqi-',
        电视: 'icon-dianshiji1',
        热水器: 'icon-haofangtuo400iconfont2reshuiqi',
        宽带: 'icon-wifi',
        沙发: 'icon-tubiaoCSban-'
      },
      pos: {
        lng: null,
        lat: null
      }
    }
  },
  async created () {
    // console.log(this.obj)
    const res = await houseInfoAPI(this.obj.houseCode)
    this.detailObj = res.data.body
    console.log(res)
    this.src = `http://liufusong.top:8080${this.detailObj.houseImg[0]}`
    console.log(this.detailObj)
    // console.log(this.detailObj.floor)
    // console.log(this.detailObj.oriented[0])
    // this.floor = this.detailObj.floor
    this.direction = this.detailObj.oriented[0]
    this.length = this.detailObj.houseImg.length
    this.pos.lng = this.detailObj.coord.longitude
    this.pos.lat = this.detailObj.coord.latitude
  },
  methods: {
    async fn () {
      this.flag = !this.flag
      if (this.flag) {
        Toast('已添加收藏')
        await favoritesHouse(this.detailObj.houseCode)
      } else {
        Toast('已取消收藏')
        await unfavoritesHouse(this.detailObj.houseCode)
      }
    }
  }
}
</script>
<style lang='less' scoped>
body {
  background-color: blue;
  .picture {
    height: 220px;
    img {
      width: 100%;
      height: 220px;
    }
  }
  .main {
    padding-left: 12px;
    margin-bottom: 10px;
    .list {
      border-bottom: 1px solid #ccc;
      width: 350px;
      padding-bottom: 15px;
      p {
        margin-bottom: 10px;
        font-size: 20px;
      }
      .second {
        display: flex;
        // justify-content: space-between;
        // vertical-align: bottom;
        padding: 15px 0;
        text-align: center;
        li {
          flex: 1;
          p {
            font-size: 18px;
            font-weight: 700;
            color: #e8634d;
            margin-bottom: 5px;
            i {
              font-style: normal;
              font-size: 13px;
            }
          }
          span {
            font-size: 13px;
            color: #999;
          }
        }
      }
      .third {
        display: flex;
        flex-wrap: wrap;
        li {
          width: 50%;
          p {
            font-size: 13px;
            color: #999;
            span {
              color: black;
            }
          }
        }
      }
    }
  }
  .houseConfiguration {
    // margin-top: 20px;
    p {
      // padding: 0 0 0 12px;
      padding: 0 12px;
      margin: 6px 0;
      font-size: 14px;
    }
    .map {
      width: 100%;
      height: 180px;
      // background-color: pink;
    }
    h5 {
      margin: 10px 0;
      font-size: 16px;
      padding: 0 12px 10px;
      // padding-bottom: 10px;
      border-bottom: 1px solid #ccc;
    }
    ul {
      display: flex;
      z-index: 98;
      // width: 375px;
      flex-wrap: wrap;
      // text-align: center;
      li {
        width: 75px;
        font-size: 16px;
        text-align: center;
        p {
          span {
            font-size: 20px;
          }
        }
      }
    }
  }
  .houseGeneral {
    min-height: 80px;
    h5 {
      margin: 10px 0;
      font-size: 16px;
      padding: 0 12px 10px;
      // padding-bottom: 10px;
      border-bottom: 1px solid #ccc;
    }
    .title {
      display: flex;
      padding-top: 10px;
      .pictrue {
        padding: 0 10px;
        width: 70px;
        img {
          width: 100%;
        }
      }
      .userName {
        width: 200px;
        font-size: 16px;
        p {
          margin: 9px 0 5px;
        }
        span {
          // margin-top: 9px;
          color: #e8634d;
          font-size: 12px;
        }
      }
      .msgBtn {
        width: 100px;
        height: 80px;
        line-height: 70px;
        text-align: center;
        span {
          // display: inline-block;
          padding: 5px 10px;
          border-radius: 3px;
          border: 1px solid #58b67f;
          color: #58b67f;
          font-size: 16px;
        }
      }
    }
    .text {
      padding: 0 12px;
      p {
        font-size: 15px;
        margin: 0;
      }
    }
  }
  .houseList {
    // width: 100%;
    min-height: 100px;
    margin-bottom: 50px;
    h5 {
      margin: 10px 0;
      font-size: 16px;
      padding: 0 12px 10px;
      // padding-bottom: 10px;
      border-bottom: 1px solid #ccc;
    }
  }
  .buttomNav {
  z-index: 99;
  position: fixed;
  bottom: 0;
  width: 100%;
  .btn1 {
    width: 33.3%;
    .btnText {
      color: #999;
    }
  }
  .btn2 {
    width: 33.3%;
    // color: #999;
    // border-left: 1px solid #999;
    // border-right: 1px solid #999;
    .btnText {
      color: #999;
    }
  }
  .btn3 {
    width: 33.3%;
    a {
      color: #fff;
    }
  }
}
}
</style>
